package scanner

import (
	"fmt"
	"time"

	"github.com/robfig/cron/v3"

	"scanner/src/config"
	"scanner/src/utils"
)

func ScannerTarget(conf config.Conf) {
	fmt.Println(conf)
	c := cron.New()

	for i := 0; i < len(conf.Config.Scanners); i++ {
		EntryID, err := c.AddJob(conf.Config.Scanners[i].Cron,
			Job1{5, conf.Config.Scanners[i].Target, conf})
		fmt.Println(time.Now(), EntryID, err)
	}
	c.Start()
}

type Job1 struct {
	timeout int16
	addr    string
	conf    config.Conf
}

func (t Job1) Run() {
	fmt.Println("telnet addr:", t.addr)
	result := utils.Telnet(t.addr, t.timeout)
	go utils.PostMetrics(t.conf, t.addr, result)
}
